﻿
@using Treca.Business.Base_SysManage;
@using Treca.Base_SysManage.Entity;
@using Treca.Base_SysManage.Entity;
@using Treca.Util;
@using EFCore.Sharding;
@inherits DependencyViewPage 
@using System.Data;
@using Microsoft.AspNetCore.Http;
@{
    Layout = "~/Views/Shared/_Layout_NewList.cshtml";
    var returnkey = (string)this.ViewData["returnkey"];
    BaseDataHelper dataHelper = (BaseDataHelper)this.ViewData["listHelper"];
    var TableName="base_searchplan";
}
@{
    var ExSearchFields = "";
    List<base_extendedfield> exss = dataHelper.GetExFileds("Base_SysManage", "base_searchplan");
    @foreach (var ex in exss)
    {
        var name = TranslateService.GetTranslate("", $@"Base_SysManage_base_searchplan_{ex.exfiled}", $@"{ex.filedname}");
        ExSearchFields+=$@"<option value='{ex.exfiled}'>{name}</option>";
    }
}
<div class="fx-content">
      <div id = "toobar" >   
           <div class="btn-group btn-group-sm">

               <form class="form-inline" id="searchForm">
                    <div class="form-group hidden" id="SearchInfo">
                        <label>查询类别</label>
                        <select class="selectpicker" id="condition" name="condition" data-style="btn-info btn-sm" data-width="100px">
                            <option value="">@TranslateService.GetTranslate("","System_Select","选择")</option>
                            
                         <option value="searchplanname">@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_searchplanname","搜索计划名称")</option>
                         <option value="userid">@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_userid","用户名")</option>
                         <option value="roleid">@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_roleid","车牌号")</option>
                         <option value="searchinfo">@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_searchinfo","查询条件")</option>
                         <option value="url">@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_url","页面")</option>
                         <option value="IsDelete">@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_IsDelete","删除标识")</option>
                         <option value="Remark">@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_Remark","描述")</option>
                         <option value="StatusFlag">@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_StatusFlag","使用状态")</option>
                         <option value="CreateOperator">@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_CreateOperator","创建人")</option>
                         <option value="ModifyOperator">@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_ModifyOperator","修改人")</option>
                         <option value="isdefault">@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_isdefault","是否设置为默认")</option>
                            @Html.Raw(ExSearchFields)
                        </select>
                        <input type="text"  class="form-control input-sm" id="keyword" name="keyword" placeholder='@TranslateService.GetTranslate("", "System_PleaseEnterKeywords", "请输入关键字")'>
                    </div>

                    <div class="form-group">
                        <button type = "button" class="btn btn-refresh" aria-label="Right Align" onclick="javascript: location.reload();">
                            <span class="iconfont icon-ysic_refresh" aria-hidden="true"></span>
                            @TranslateService.GetTranslate("", "System_Flash", "刷新")
                        </button>
                        <button type="button" class="btn btn-normal" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
                            <i class="iconfont icon-ysic_searchSel"></i>
                            @TranslateService.GetTranslate("", "System_SearchPanel", "搜索条件")
                        </button>
                    </div>
                </form>
        </div>
    </div>
</div>
<div class="fx-wrapper">
    <div class="panel panel-info" id="SearchPanel">
        <div class="panel-heading" role="tab" id="headingThree" style="display: none;">
            <h4 class="panel-title">
                <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
                 @TranslateService.GetTranslate("", "System_SearchPanel", "搜索条件")
                </a>
            </h4>
        </div>
        <div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
            <div class="panel-body">
                <div id="builder"></div>
                <script>
                    var searchurl="/Base_SysManage/base_searchplan/GetDataListByComplexQuery?TableName=@TableName";
                    var searchmode="ComplexQuery";
                    var rules_basic = {
                    };
                    $.postJSON('/Base_SysManage/base_searchplan/ComplexQueryFilters?TableName=@TableName', {}, function (resJson) {
                                loading(false);
                                if (resJson.Success) {
                                       $('#builder').queryBuilder({
                                            plugins: {
                                               'bt-selectpicker': { liveSearch: true },//引用了selectpicker
                                                'bt-tooltip-errors': { delay: 100 },
                                           },
                                           //operators: ['equal', 'greater', 'less', 'greater_or_equal', 'less_or_equal', 'not_equal', 'contains', 'not_contains', 'in', 'not_in',
                                           //    'is_empty', 'is_null', 'is_not_empty', 'is_not_null'],
                                           operators: [
                                               { type: 'contains', apply_to: ['string', 'number', 'boolean'] },
                                               { type: 'equal', apply_to: ['string', 'number','boolean'] },
                                               { type: 'greater', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                               { type: 'less', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                               { type: 'greater_or_equal', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                               { type: 'less_or_equal', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                               { type: 'not_equal', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                               { type: 'not_contains', apply_to: ['string', 'number', 'boolean'] },
                                               { type: 'in', apply_to: ['string', 'number', 'boolean'] },
                                               { type: 'not_in', apply_to: ['string', 'number', 'boolean'] },
                                               { type: 'is_empty', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                               { type: 'is_null', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                               { type: 'is_not_empty', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                               { type: 'is_not_null', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                               { type: 'between' },
                                               { type: 'not_between' },
                                           ],
                                           filters: resJson.Data,
                                            //rules: rules_basic,
                                            lang_code: 'zh-CN',
                                            icons: {
                                                add_group:    'iconfont icon-ysic_add',
                                                add_rule:     'iconfont icon-ysic_add',
                                                remove_group: 'iconfont icon-ysic_delete',
                                                remove_rule:  'iconfont icon-ysic_delete'
                                            }
                                        });

                                        // 添加搜索按钮
                                    var searchBtn = $('<button style="margin-right:50px"><i class="iconfont icon-ysic_search"></i>@TranslateService.GetTranslate("", "System_Search", "查询")</button>');
                                        searchBtn.attr("type", "button");
                                        searchBtn.addClass("btn btn-primary");
                                        searchBtn.attr("onclick", "javascript: $('#dataTable').bootstrapTable('refresh', { silent: true,pageNumber:1 });");
                                    $("#builder .rules-group-header").append(searchBtn);
                                }
                                else {
                                    searchurl="/Base_SysManage/base_searchplan/GetDataListBySearchInfo?TableName=@TableName";
                                    searchmode="SearchInfo";
                                    $('#SearchInfo').removeClass("hidden");
                                    $('#SearchPanel').addClass("hidden");
                                    $('#dataTable').bootstrapTable('refresh', { url:searchurl });
                                }
                             });
                </script>
            </div>
        </div>
    </div>
</div> 
    <div class="fx-wrapper">
        <table id="dataTable" class="table-bordered"></table>
    </div>
@{
    var ExFields = "";
    List<base_extendedfield> exfs = dataHelper.GetExFileds("Base_SysManage", "base_searchplan");
    @foreach (var ex in exfs)
    {
        var name = TranslateService.GetTranslate("", $@"Base_SysManage_base_searchplan_{ex.exfiled}", $@"{ex.filedname}");
        ExFields+=$@"{{ title: '{name}', field: '{ex.exfiled}', width: '5%' }},";
    }
}
<script>
    var $table = $('#dataTable');
    $(function () {
        initTable();
    });

    //初始化表格
    function initTable() {
        $table.bootstrapTable({
            url: '/Base_SysManage/base_searchplan/GetDataListByComplexQuery',
            idField: 'Id',
            method: 'post',
            contentType: 'application/json',
            queryParamsType: '',
            clickToSelect: false,
            pagination: true,
            sidePagination: "server",
            pageNumber: 1,
            pageSize: 30,
            pageList: [10, 30, 60, 100],
            onCheck: function (row) {
                window.chekcCode = row['@returnkey.Split(',')[0]'];
                window.chekcName = row['@returnkey.Split(',')[1]'];
            },
            onUncheck: function (row) {  window.chekcName = '' ; window.chekcCode = '' ;},
            columns: [
                { title: 'ck', field: 'ck', checkbox: true, width: '3%' },
                    { title: '@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_searchplanname","搜索计划名称")', field: 'searchplanname', width: '5%' },
                    { title: '@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_userid","用户名")', field: 'userid', width: '5%' },
                    { title: '@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_roleid","车牌号")', field: 'roleid', width: '5%' },
                    { title: '@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_searchinfo","查询条件")', field: 'searchinfo', width: '5%' },
                    { title: '@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_url","页面")', field: 'url', width: '5%' },
                    { title: '@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_Remark","描述")', field: 'Remark', width: '5%' },
                    { title: '@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_CreateDate","创建日期")', field: 'CreateDate', width: '5%' },
                    { title: '@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_CreateOperator","创建人")', field: 'CreateOperator', width: '5%' },
                    { title: '@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_ModifyDate","修改日期")', field: 'ModifyDate', width: '5%' },
                    { title: '@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_ModifyOperator","修改人")', field: 'ModifyOperator', width: '5%' },
                    { title: '@TranslateService.GetTranslate("","Base_SysManage_base_searchplan_isdefault","是否设置为默认")', field: 'isdefault', width: '5%' },
                @Html.Raw(ExFields)
                 {title: '使用状态', formatter: function (value, row, index) {
                        if (row.StatusFlag == '1') {
                            return '<span class="badge badge-primary">@TranslateService.GetTranslate("","System_Approve_Flag","已审核")</span>';
                        } if (row.StatusFlag == '2') {
                                return '<span class="badge badge-primary">@TranslateService.GetTranslate("","System_Reverse_Flag","反审核")</span>';
                        }if (row.StatusFlag == '0') {
                                return '<span class="badge badge-primary">@TranslateService.GetTranslate("","System_UnApprove_Flag","未审核")</span>';
                        }  
                    }}
            ],onPreBody: function (data) {
                for(var i=0,l=data.length;i<l;i++){
                    for(var key in data[i]){
                        if (data[i][key + "__Name"] != null) {
                            data[i][key] = data[i][key + "__Name"];
                        }
                    }
                }
            },
            queryParams: function (params) {
                if(searchmode=="ComplexQuery"){
                    try {
                        var result = $('#builder').queryBuilder('getRules');
                        return { pagination: params,ComplexQuerys: result };
                    } catch (e) {
                        return { pagination: params };
                    }
                }else{
                    var condition = $("#condition").val();
                    var keyword = $("#keyword").val();
                    var searchParams = [];
                    if (condition != '' && condition != null && keyword != '' && keyword!=null)
                    {
                        var searchinfo = new SearchInfo();
                        searchinfo.FiledName = condition;
                        searchinfo.Value = keyword;
                        searchParams.push(searchinfo);
                    }
                    var values = $('#searchForm').getValues();
                        for (var item in values)
                    {
                        if (item == 'condition' || item == 'keyword' || values[item] == '' || values[item]== null) continue;
                        var Operate = $('#searchForm').find('#' + item).attr('Operate');
                        if (Operate == null) Operate = '包含';
                        var searchinfo = new SearchInfo();
                        searchinfo.FiledName = item;
                        searchinfo.Value = values[item];
                        searchinfo.Operate = Operate;
                        searchParams.push(searchinfo);
                    }
                    return { pagination:params,searchInfos: searchParams }; 
                }
            }
        });
    }



</script>
